package cn.com.cloudpioneer.evaluate.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @auther maruikai
 * @create 2023/9/19-15:18
 */
public class FileUtils {

    public static File toFile(String fileName, InputStream in) {
        File file = new File(fileName);
        try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
            int bytesRead = 0;
            int cacheSize = 2048;
            byte[] buffer = new byte[cacheSize];
            while ((bytesRead = in.read(buffer, 0, cacheSize)) != -1) {
                fileOutputStream.write(buffer, 0, bytesRead);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return file;
    }

}
